package com.waypolice.manager.service.impl;

import com.waypolice.common.pojo.TaotaoResult;
import com.waypolice.manager.service.SearchSetService;
import com.waypolice.manager.service.UpmsArchivesTypesService;
import com.waypolice.manager.service.UpmsDictionaryService;
import com.waypolice.manager.service.YearArchiveHappenService;
import com.waypolice.mapper.CmsJudItemMapper;
import com.waypolice.mapper.CmsJudVolumeMapper;
import com.waypolice.mapper.CmsSinItemMapper;
import com.waypolice.mapper.UpmsDictionaryMapper;
import com.waypolice.mapper.handwriting.YearArchiveHappenMapperSon;
import com.waypolice.pojo.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description 检索范围设置
 * @Author zhangruyi
 * @Date Created in 13:48 2019/5/30
 * @Modified By:
 */
@Service
public class SearchSetServiceImpl implements SearchSetService {
    private static final Logger LOGGER = LoggerFactory.getLogger(SearchSetServiceImpl.class);

    @Autowired
    private UpmsDictionaryMapper upmsDictionaryMapper;
    @Autowired
    private UpmsDictionaryService upmsDictionaryService;



    @Override
    public TaotaoResult searchScopeClean(String chooseSet) {
        TaotaoResult result = new TaotaoResult();
        List<UpmsDictionary> searchScopes = upmsDictionaryService.findAllSearchScope();
        if(searchScopes.isEmpty()){
            result.setStatus(101);
        }else{
            UpmsDictionaryExample upmsDictionaryExample = new UpmsDictionaryExample();
            UpmsDictionaryExample.Criteria criteria = upmsDictionaryExample.createCriteria();
            int i = 0;
            if("0".equals(chooseSet)){
                for (UpmsDictionary searchScope:searchScopes) {
                        searchScope.setStr2("0");
                        searchScope.setMtime(new Date());
                    i = upmsDictionaryMapper.updateByPrimaryKey(searchScope);
                    if(i != 1){
                        result.setStatus(101);
                    }else{
                        result.setStatus(200);
                    }
                }
            }else {
                for (UpmsDictionary searchScope:searchScopes) {
                    if(searchScope.getCode().equals(chooseSet)){
                        searchScope.setStr2("1");
                        searchScope.setMtime(new Date());
                       i = upmsDictionaryMapper.updateByPrimaryKey(searchScope);
                        if(i != 1){
                            result.setStatus(101);
                        }else{
                            result.setStatus(200);
                        }
                    }else{
                        searchScope.setStr2("0");
                        searchScope.setMtime(new Date());
                       i = upmsDictionaryMapper.updateByPrimaryKey(searchScope);
                        if(i != 1){
                            result.setStatus(101);
                        }else{
                            result.setStatus(200);
                        }
                    }
                }
            }
        }
        return result;
    }
}
